package com.cy.pj.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author 张琪
 * @date 2020/11/12
 * @describe 通过该类来演示切面中各种通知(advice)方法的执行顺序
 */
@Aspect
@Component
public class SysTimeAspect {
    @Pointcut("bean(categoryServiceImpl)")
    public void doTime() {}

    @Before("doTime()")
    public void doBefore() {
        System.out.println("SysTimeAspect.doBefore");
    }

    @AfterReturning("doTime()")
    public void doAfterReturning() {
        System.out.println("SysTimeAspect.doAfterReturning");
    }

    @AfterThrowing("doTime()")
    public void doAfterThrowing() {
        System.out.println("SysTimeAspect.doAfterThrowing");
    }

    @After("doTime()")
    public void doAfter(){
        System.out.println("SysTimeAspect.doAfter");
    }

    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("SysTimeAspect.doAround ....A");
        Object result = joinPoint.proceed();
        System.out.println("SysTimeAspect.doAround ....B");
        return result;
  }
}
